package day_4;
import day_4.Student;

import java.util.ArrayList;
import java.util.Scanner;

public class StudentSystem {
    public static void main(String[] args) {
        ArrayList<Student> list = new ArrayList<>();
        Student init = new Student();
        init.name ="张三"; init.age=11;init.id=111;
        list.add(init);
        Student init1 = new Student();
        init1.name ="李四"; init1.age=22;init1.id=222;
        list.add(init1);
        Student init2 = new Student();
        init2.name ="王五"; init2.age=33;init2.id=333;
        list.add(init2);


        int flag = 0;
        while(flag !=5){
            flag = menu();
            if(flag !=5){
                if(flag == 1){
                   Student student = add();
                   list.add(student);
                    System.out.println("-------添加成功,返回主菜单-------");
                }
                if(flag==2){
                    int age = UpdateAllAge();
                    for (int i = 0; i < list.size(); i++) {
                        Student student = list.get(i);
                        student.age = age;
                        list.set(i,student);
                    }
                }
                if(flag==3){
                    System.out.println("-----------------");
                    for (int i = 0; i < list.size(); i++) {
                        show(list.get(i));
                    }
                }
                if(flag==4){
                    Scanner sc = new Scanner(System.in);
                    System.out.println("请输入学号");
                    int id = sc.nextInt();
                    boolean flag1 = false;
                    for (int i = 0; i < list.size(); i++) {
                        Student student = list.get(i);
                        if(student.id == id){
                            show(student);
                            flag1 = true;
                        }
                    }
                    if(flag1==false)
                        System.out.println("没有学号为"+id+"的学生!!!");
                }else System.out.println("没有此目录号请重新输入");
            }
        }
    }
    public static int menu(){
        System.out.println("学生管理系统");
        System.out.println("1.新增学生信息");
        System.out.println("2.更换所有同学的年龄信息");
        System.out.println("3.展示所有同学信息");
        System.out.println("4.通过学号查询学生信息");
        System.out.println("5.退出");
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入目录号");
        int i = sc.nextInt();
        if(i == 1){
            return 1;
        } else if (i==2) {
            return 2;
        } else if (i==3) {
            return 3;
        } else if (i==4) {
            return 4;
        } else if (i==5) {
            return 5;
        }else {
            return 0;
        }
    }
    public static Student add(){
        Student student = new Student();
        Scanner sc = new Scanner(System.in);
        System.out.println("**学生信息添加**");
        System.out.println("待添加学生姓名");
        student.name = sc.next();
        System.out.println("待添加学生学号");
        student.id = sc.nextInt();
        System.out.println("待添加学生年龄");
        student.age = sc.nextInt();
        System.out.println("正在添加");
        return student;
    }
    public static int UpdateAllAge(){
        System.out.println("请输入更新后的年龄信息");
        Scanner sc = new Scanner(System.in);
        return sc.nextInt();
    }
    public static void show(Student stu){
        System.out.println("学号:"+ stu.id);
        System.out.println("姓名:"+ stu.name);
        System.out.println("年龄:"+ stu.age);
        System.out.println("-----------------");
    }
}
